var errMsg="";

function strltrim() {
return this.replace(/^\s+/,'');
}

function strrtrim() {
return this.replace(/\s+$/,'');
}
function strtrim() {

return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

//validations for email
var errMsg="";
function ValidateMail(x)
{
  
	var Cont_Value=x;
	var pos=-1;
	var dotpos=0;
	var charpos=0;
	var occat=0;
	var occdot=0;
	var diff=0;
	if (Cont_Value!="")
	{
		for(var i=0;i<Cont_Value.length;i++)
		{
			var c=Cont_Value.charAt(i);
			if( (i==0) && ((c == '@')||(c == '.')) )
			{
				errMsg="Enter valid E-Mail Address ";
				return false;
			}
			if (c == '@')          
			{	
				occat++ ;          
			}
			else if(c == '.')        
			{
				occdot++;                 
			}	
		}
		if(occat != 1 || occdot == 0  )
		{
			errMsg="Enter valid E-Mail Address";
			return false;	
		} 
		for(var i=0;i<Cont_Value.length;i++)
		{
			var c=Cont_Value.charAt(i);
			if(c=='@')
			{
		    charpos=i;//Cont_Value.indexOf("@");
		    //errMsg="character Position is"+charpos;
			}
		    if(c=='.')
		    {
		     dotpos =i; 
		     //errMsg="Dot Position is"+dotpos;
		    }
			if(dotpos!=0 && charpos!=0)
			{
			  // condition to check whether dotposition is less than character position
		      if ((dotpos<charpos) && ((dotpos-charpos)<=1))	
		      { 
		      var ch = Cont_Value.charAt(dotpos+1);

			  if(ch=='@')
			   {
		         errMsg="Enter valid E-Mail Address ";
		         return false;
                }
		      }	
              
			 if ((dotpos>charpos) && ((dotpos-charpos)>=1))	
		      {  
		       var ch = Cont_Value.charAt(charpos+1);
			   if(ch=='.')
			   {
		       errMsg="Enter valid E-Mail Address ";
		       return false;
               }
		      }
		    }

		 }
          var ch1=Cont_Value.charAt(Cont_Value.length-1)
		
		  if(ch1=='@' || ch1=='.')
			  {
		       errMsg="Enter valid E-Mail Address ";
		       return false;
              }
		

		
	}

}
//added by varma on 15jun2004
function ValidEMail(email)
 {
   ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < email.length ;i++)
    {
    if(ok.indexOf(email.charAt(i))<0){
    errMsg="Enter valid E-Mail Address ";
    return false;
    }
    }

    if (document.images)
    {
    re = /(@.*@)|(\.\.)|(\.\@)|(\_\@)|(\-\@)|(\@\-)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
    re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if (!email.match(re) && email.match(re_two)) {
        return (-1);
        }

    }
 }
// email validations
function checkemail(str){
var len = str.length ;
for(i=0;i<len;i++)
{
	var ch = str.charAt(i);
	if ((!((ch >= "A" && ch <= "Z" ) || (ch >= "a" && ch <= "z") || (ch >= 0 && ch <=9) || (ch=="@") || (ch=='.') ||(ch=="_")))
	|| (ch==" ")  )

			{	
				errMsg="Enter valid Email";
				return false;
			}
}


}


function isValidMailID(input,control,compulsory)
{	
	var Cont_Value=input;
	var Cont_Name=control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	
	
  //else if (ValidateMail(Cont_Value)==false || chkBlankSpaces1(Cont_Value)== false || checkemail(Cont_Value)==false )
   else if( Cont_Value != '' )   //modified by varma(15jun2004)
   {
       if ( ValidEMail(Cont_Value) )
        {
          return true;
        }
   }
	else 
		return true;
}


//*******  Start of Script dd/mm/yyyy********************************* 
function convert_date(field1)
{
//var Cont_Name=control;
//var Cont_Validate=compulsory;
var fLength = field1.value.length;// Length of supplied field in characters.
var divider_values = new Array ('-','.','/',' ',':','_',','); // Array to hold permitted date seperators.  Add in '\' value
var array_elements = 7; // Number of elements in the array - divider_values.
var day1 = new String(null); // day value holder
var month1 = new String(null); // month value holder
var year1 = new String(null); // year value holder
var divider1 = null; // divider holder
var outdate1 = null; // formatted date to send back to calling field holder
var counter1 = 0; // counter for divider looping 
var divider_holder = new Array ('0','0','0'); // array to hold positions of dividers in dates
var s = String(field1.value); // supplied date value variable

/*	if ((Cont_Validate=="Y") &&(fLength == 0))
	{
		errMsg=Cont_Name + "   cannot be blank";
		field1.focus();
		field1.select();
		return false
	}*/
	//If field is empty do nothing
	if ( fLength == 0 ){
		errMsg= field1.name+" Can Not be blank";
		field1.focus();
		field1.select();
		return false;
	}
	// Deal with today or now
	if ( field1.value.toUpperCase() == 'NOW' || field1.value.toUpperCase() == 'TODAY' ) {
		var newDate1 = new Date();
		if (navigator.appName == "Netscape") {
    		var myYear1 = newDate1.getYear() + 1900;
  		}
  		else {
  			var myYear1 =newDate1.getYear();
  		}
  	var myMonth1 = newDate1.getMonth()+1;  
	var myDay1 = newDate1.getDate();
	field1.value = myDay1 + "/" + myMonth1 + "/" + myYear1;
	fLength = field1.value.length;//re-evaluate string length.
	s = String(field1.value)//re-evaluate the string value.
}

//Check the date is the required length
if ( fLength != 0 && (fLength < 6 || fLength > 11) ) {
	invalid_date(field1);
	return true;   
	}

// Find position and type of divider in the date
for ( var i=0; i<3; i++ ) {
	for ( var x=0; x<array_elements; x++ ) {
		if ( s.indexOf(divider_values[x], counter1) != -1 ) {
			divider1 = divider_values[x];
			divider_holder[i] = s.indexOf(divider_values[x], counter1);
		   //errMsg=i + " divider1 = " + divider_holder[i];
			counter1 = divider_holder[i] + 1;
			//errMsg=i + " counter1 = " + counter1;
			break;
		}
 	}
 }

// if element 2 is not 0 then more than 2 dividers have been found so date is invalid.
if ( divider_holder[2] != 0 ) {
   invalid_date(field1);
	return false;   
}

// See if no dividers are present in the date string.
if ( divider_holder[0] == 0 && divider_holder[1] == 0 ) { 
   
		//continue processing
		if ( fLength == 6 ) {//ddmmyy
   		day1 = field1.value.substring(0,2);
     		month1 = field1.value.substring(2,4);
  			year1 = field1.value.substring(4,6);
  			if ( (year1 = validate_year(year1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
			}
			
		else if ( fLength == 7 ) {//ddmmmy
   		day1 = field1.value.substring(0,2);
  			month1 = field1.value.substring(2,5);
  			year1 = field1.value.substring(5,7);
  			if ( (month1 = convert_month(month1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
  			if ( (year1 = validate_year(year1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
			}
		else if ( fLength == 8 ) {//ddmmyyyy
   		day1 = field1.value.substring(0,2);
  			month1 = field1.value.substring(2,4);
  			year1 = field1.value.substring(4,8);
			}
		else if ( fLength == 9 ) {//ddmmmyyyy
   		day1 = field1.value.substring(0,2);
  			month1 = field1.value.substring(2,5);
  			year1 = field1.value.substring(5,9);
  			if ( (month1 = convert_month(month1)) == false ) {
   			invalid_date(field1);
				return false; 
				}
			}
		
		if ( (outdate1 = validate_date(day1,month1,year1)) == false ) {
   		errMsg="The value " + field1.value + " is not a vaild date.\n\r Please enter a valid date in the format dd/mm/yyyy";
			field1.focus();
			field1.select();
			return false;
			}

		field1.value = outdate1;
		return true;// All OK
		}
		
// 2 dividers are present so continue to process	
if ( divider_holder[0] != 0 && divider_holder[1] != 0 ) { 	
  	day1 = field1.value.substring(0, divider_holder[0]);
  	month1 = field1.value.substring(divider_holder[0] + 1, divider_holder[1]);
  	//errMsg=month1;
  	year1 = field1.value.substring(divider_holder[1] + 1, field1.value.length);
	
	}

if ( isNaN(day1) && isNaN(year1) ) { // Check day and year are numeric
	invalid_date(field1);
	return false;  
   }

if ( day1.length == 1 ) { //Make d day dd
   day1 = '0' + day1;  
	}

if ( month1.length == 1 ) {//Make m month mm
	month1 = '0' + month1;   
	}

if ( year1.length == 2 ) {//Make yy year yyyy
   if ( (year1 = validate_year(year1)) == false ) 
		{
   		invalid_date(field1);
		return false;  
		}
	}

if ( month1.length == 3 || month1.length == 4 ) {//Make mmm month mm
   if ( (month1 = convert_month(month1)) == false) {
   	errMsg="month1" + month1;
   	invalid_date(field1);
   	return false;  
   }
}

// Date components are OK
if ( (day1.length == 2 || month1.length == 2 || year1.length == 4) == false) {
   invalid_date(field1);
   return false;
}

//Validate the date
if ( (outdate1 = validate_date(day1, month1, year1)) == false ) {
   errMsg="The value " + field1.value + " is not a vaild date.\n\r Please enter a valid date in the format dd/mm/yyyy";
	field1.focus();
	field1.select();
	return false;
}

// Redisplay the date in dd/mm/yyyy format
field1.value = outdate1;
return true;//All is well

}
function convert_month(monthIn) 
{
	var month_values = new Array 	("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
	monthIn = monthIn.toUpperCase(); 
	if ( monthIn.length == 3 ) {
		for ( var i=0; i<12; i++ ) 
		{
   			if ( monthIn == month_values[i] ) 
   				{
					monthIn = i + 1;
					if ( i != 10 && i != 11 && i != 12 ) 
						{		
   							monthIn = '0' + monthIn;
						}
						return monthIn;
				}
		}
		}

else if ( monthIn.length == 4 && monthIn == 'SEPT') {
   monthIn = '09';
   return monthIn;
	}
	
else {
	return false;
	} 
}

function invalid_date(inField) 
{
errMsg="The value " + inField.value + " is not in a vaild date format.\n\r Please enter date in the format dd/mm/yyyy";
inField.focus();
inField.select();
return true;   
}

function validate_date(day2, month2, year2)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
var DayArray = new Array(31,28,31,30,31,30,31,31,30,31,30,31);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
var inpDate = day2 + month2 + year2;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
var filter=/^[0-9]{2}[0-9]{2}[0-9]{4}$/;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

//Check ddmmyyyy date supplied
if (! filter.test(inpDate))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
  {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
  return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
  }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
/* Check Valid Month */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
if (! filter.test(month2))                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
  {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
  }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
/* Check For Leap Year */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
var N = Number(year2);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
   DayArray[1]=29;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
  	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
/* Check for valid days for month */                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
for(var ctr=0; ctr<=11; ctr++)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
  	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
   if (MonthArray[ctr]==month2)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
   	{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
      if (day2<= DayArray[ctr] && day2 >0 )                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
        {
        inpDate = day2 + '/' + month2 + '/' + year2;       
        return inpDate;
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
      else                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
        {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
        return false;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
   	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
   }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
}
function validate_year(inYear) 
{
if ( inYear < 10 ) 
	{
   inYear = "20" + inYear;
   return inYear;
	}
else if ( inYear >= 10 )
	{
   inYear = "19" + inYear;
   return inYear;
	}
else 
	{
	return false;
	}   
}
//******* End of Script dd/mm/yyyy********************************* 
// function to validate date in "mm/dd/yyyy" format

function chkDate(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;


	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg="<li> " + Cont_Name + " cannot be blank";
		return false;
	}
	else if (Cont_Value!="")
	{	
		var strdate=Cont_Value
		var intstart=0
		var intsep=0
		var intcount=0
		var intdate=new Array(2)

		while (intsep!=-1)
		{
			intsep=strdate.indexOf("/",intstart);
			if (intsep==-1) 
				intdate[intcount]=strdate.substr(intstart)
			else	
				intdate[intcount]=strdate.substr(intstart,intsep-intstart)
			intstart=intsep+1
			intcount=intcount+1
		}
		
		var d=new Date(strdate);
		if ((intdate[0]!=d.getMonth()+1) || (intdate[1]!=d.getDate()) || (intdate[2]!=d.getFullYear()))
		{
			
			//errMsg="<li> " + Cont_Name +" should be in 'mm/dd/yyyy' format";
			errMsg="<li> Please enter valid " + Cont_Name ;
			return false;			
		}
		
		if((intdate[2].length>4) || (intdate[2].length <4) || ( (intdate[2]<1900) || (intdate[2]>4712) ) )
              {
				
			  errMsg="<li> " + Cont_Name +" Enter four digit year that should be in the range of 1900 - 4712";
               return false;
              }
	}

	return true;
}

function chkScheduleRevisedDate(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;


	/*if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg="<li> " + Cont_Name + " cannot be blank";
		return false;
	}*/
	
	 if( (Cont_Value!="") || (Cont_Value.length !=0) )
	{	
		var strdate=Cont_Value
		var intstart=0
		var intsep=0
		var intcount=0
		var intdate=new Array(2)

		while (intsep!=-1)
		{
			intsep=strdate.indexOf("/",intstart);
			if (intsep==-1) 
				intdate[intcount]=strdate.substr(intstart)
			else	
				intdate[intcount]=strdate.substr(intstart,intsep-intstart)
			intstart=intsep+1
			intcount=intcount+1
		}
		
		var d=new Date(strdate);
		if ((intdate[0]!=d.getMonth()+1) || (intdate[1]!=d.getDate()) || (intdate[2]!=d.getFullYear()))
		{
			
			//errMsg="<li> " + Cont_Name +" should be in 'mm/dd/yyyy' format";
			errMsg="<li> Please enter valid " + Cont_Name ;
			return false;			
		}
		
		if((intdate[2].length>4) || (intdate[2].length <4) || ( (intdate[2]<1900) || (intdate[2]>4712) ) )
              {
				
			  errMsg="<li> " + Cont_Name +" Enter four digit year that should be in the range of 1900 - 4712";
               return false;
              }
	}

	return true;
}



// function to compare date, validate format, check for Not Null or Null
function ValidateLeadDate(Linput,input,control,control1,compulsory)
{
	var dtmBidDate=Linput;
	var dtmLeadDate=input;
	Cont_Value=input;
	Cont_Name=control;
	Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	else if (Cont_Value!="")
	{
		var Byear
		var Lyear
		var Lmon
		var Bmon
		var Lday
		var Bday
	
		var MonPosLDate = dtmLeadDate.indexOf("/",-1)
		var DayPosLDate= dtmLeadDate.lastIndexOf("/")
	
		var MonPosBDate = dtmBidDate.indexOf("/",-1)
		var DayPosBDate= dtmBidDate.lastIndexOf("/")
			
		Lyear=dtmLeadDate.substr(eval(DayPosLDate+1),4)
		Byear=dtmBidDate.substr(eval(DayPosBDate+1),4)
	
		Lmon=dtmLeadDate.substr(0,MonPosLDate)
		Bmon=dtmBidDate.substr(0,MonPosBDate)

		Lday=dtmLeadDate.substr(eval(MonPosLDate+1),eval(DayPosLDate-MonPosLDate-1))
		Bday=dtmBidDate.substr(eval(MonPosBDate+1),eval(DayPosBDate-MonPosBDate-1))
		
		if (eval(Lyear)>eval(Byear))
		{
			return true;
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)>eval(Bmon)))
		{
			return true;
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)>eval(Bday)))
		{
			return true;
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)==eval(Bday)))
		{
			return true;
		}
		else
		{
			errMsg=Cont_Name + " cannot be less than "+Linput;
			return false;
		}

	}
	else
		return true;
}

//
function ValidateLeadDate1(Linput,input,control,compulsory)
{
	var dtmBidDate=Linput;
	var dtmLeadDate=input;
	Cont_Value=input;
	Cont_Name=control;
	Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	else if((chkDate(dtmLeadDate,Cont_Name,Cont_Validate)== false))
	{
		return false;
	}
	else if (Cont_Value!="")
	{
		var Byear
		var Lyear
		var Lmon
		var Bmon
		var Lday
		var Bday
	
		var MonPosLDate = dtmLeadDate.indexOf("/",-1)
		var DayPosLDate= dtmLeadDate.lastIndexOf("/")
	
		var MonPosBDate = dtmBidDate.indexOf("/",-1)
		var DayPosBDate= dtmBidDate.lastIndexOf("/")
			
		Lyear=dtmLeadDate.substr(eval(DayPosLDate+1),4)
		Byear=dtmBidDate.substr(eval(DayPosBDate+1),4)
	
		Lmon=dtmLeadDate.substr(0,MonPosLDate)
		Bmon=dtmBidDate.substr(0,MonPosBDate)

		Lday=dtmLeadDate.substr(eval(MonPosLDate+1),eval(DayPosLDate-MonPosLDate-1))
		Bday=dtmBidDate.substr(eval(MonPosBDate+1),eval(DayPosBDate-MonPosBDate-1))
	
		if (eval(Lyear)>eval(Byear))
		{
			return true;
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)>eval(Bmon)))
		{
			return true;
		}
		else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)>eval(Bday)))
		{
			return true;
		}
		else
		{
			errMsg=Cont_Name + " cannot be less than or equal to Bid date";
			return false;
		}

	}
	else
		return true;
}
function checkzero(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;

	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}

	 
	 else if (Cont_Value!="")
	{
		
		if(  parseInt(Cont_Value) <=0 ) 
		{
		   	errMsg=Cont_Name + " cannot be less than or equal to Zero ";
			return false;
		}	

		for(i=0;i<Cont_Value.length;i++)
			{
				var ch  = Cont_Value.charAt(i);
				if(ch=='.')
				  {
					errMsg=Cont_Name + " cannot contain decimals";
					return false;
				 }
                        }
	}
	else
		return true;
}


function checkInteger(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;

	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		//errMsg =errMsg+"|";
		errMsg = Cont_Name + " cannot be blank" ;
		return false;
	}


	//else if (Cont_Value!="")
	//{
	//
	//	if(  parseInt(Cont_Value) < 0 )
	//	{
	//		//errMsg = errMsg +"|";
	//	   	errMsg = Cont_Name + " cannot be less than Zero ";
	//		return false;
	//	}
	//
	//	for(i=0;i<Cont_Value.length;i++)
	//		{
	//			var ch  = Cont_Value.charAt(i);
	//			if(ch=='.')
	//			  {
	//				//errMsg =errMsg+"|";
	//				errMsg = Cont_Name + " cannot contain decimals";
	//				return false;
	//			 }
          //              }
	//}
	else if (Cont_Value!="")
	{    // Changed by Basha 26th June 2003
	    if(isNaN(Cont_Value))
			{
				errMsg = "Enter valid Integer number in " + Cont_Name;
				return false;
			}

		if(Cont_Value.length > 1)
		{
		    if( (Cont_Value.trim()).charAt(0) == 0 )
		    {
		        errMsg = "Prefix Zero is not valid in " + Cont_Name;
		        return false;
		    }
		}

		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
           	if ( (!(str >= 0 && str <=9) ) || (str ==" ") )
			{

				errMsg = "Enter valid Integer number in " + Cont_Name;
				return false;
			}
		}
	}
	else
		return true;
}


//checking for amount
function checkFloat(input,control,compulsory)
{
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	var Cont_Value = input;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}

	else if (Cont_Value!="")
		{
			if(isNaN(Cont_Value) || (Cont_Value.charAt(0)==" ")|| ((Cont_Value.charAt(0)==0) && (Cont_Value.charAt(1) != "."))  )
			{
				errMsg=Cont_Name + " should be valid number and first digit can not be space or zero ";
				return false;
			}	
			for(i=0;i<Cont_Value.length;i++)
			{
				var ch  = Cont_Value.charAt(i);
				if(ch=='.')
				 	 {
						var substr=Cont_Value.substring(i+1,Cont_Value.length);
					
						if(substr.length > 4) //todo need to get from the configuration
							{
								errMsg=Cont_Name + " can contain only max four decimals ";
					
								return false;
							}
				 		}
              }
			if(Cont_Value<0)
			{
				errMsg=Cont_Name + " can not be less than zero ";
				return false;
			}
			return true;	
						
		}
		else
		return true;
}
// checking for only charcters 
function isValidAlphaNum(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	//var flag=false;
	var spcount=0;
	
	for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if (str==" ") spcount++;
			if (!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") || (str == " ") || (str == ".")))
			{	
			  errMsg=Cont_Name + " can contain only Characters";
			    //flag = false;                           
			}

		}
	if ((spcount==i) && (i != 0))
		//flag=false;

		return false;
}
//function alphaNumaric with some special charecters
function alphanumSpecial(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		errMsg= Cont_Name + " cannot be blank";
		return false;
	}
	
	else if (Cont_Value!="")
	{
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if (!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") ||(str == " ") || (str >= 0 && str <=9)|| (str=='.') || (str==',')||(str=="_")||(str=="@") || (str=='#')|| (str=='/') || (str=='\\') || (str=="-")|| (str=='+')))
			{	
				errMsg = "Enter alphabets or integers or valid special characters in " + Cont_Name;
				return false;
			}
		}
	}
	else 
		return true;
	return true;
}

//function alphaNumaricSpecial with some special charecters
function alphanumSpecialChar (input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		errMsg= Cont_Name + " cannot be blank";
		return false;
	}
	
	else if (Cont_Value!="")
	{
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if ( (str == "<") ||  (str==">") || (str=="%") )
			{	
				errMsg = "Special characters   <,>,%  are not allowed in " + Cont_Name;
				return false;
			}
		}
	}
		
	else 
		return true;
}

// function to validate e mail id 
// function to check first letter blank spaces
function frtBlankSpaces(input,control,compulsory)
{	
	var Cont_Value=input;
	var Cont_Name=control;
	var Cont_Validate=compulsory;
	var str=Cont_Value.charAt(0)
		if (str == " ")
		{	
			errMsg=Cont_Name+"   First character cannot be blank";
			return false;

		}
	}
	function chkBlankSpaces1(input)
{	
	var Cont_Value=input;
		
	for(i=0;i<Cont_Value.length;i++)
	{
		var str=Cont_Value.charAt(i)
		if (str == " ")
		{	
			errMsg=input+" Can not conatain blank spaces";
			return false;

		}
		
	}
	
	
	
}
// function to check blank spaces

function chkBlankSpaces(input,control,compulsory)
{	
	var Cont_Value=input;
	var Cont_Name=control;
	var Cont_Validate=compulsory;
	var intcheckblank=0;
		
	for(i=0;i<Cont_Value.length;i++)
	{
		var str=Cont_Value.charAt(i)
		if (str == " ")
		{	
			intcheckblank=intcheckblank+1
			
		}
	}
	
	if (intcheckblank >= Cont_Value.length)
	{
	//errMsg=Cont_Name+" Can not conatain blank spaces";
		return false;
	}
	else
	{
		return true;
	}	
	
}
	

// function to check only alphabets and numbers

function AlphaNum(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") && (chkBlankSpaces(Cont_Value,Cont_Name,Cont_Validate)==false))
	{
			errMsg=Cont_Name + " cannot be blank";
			return false;
	}
	else if ((Cont_Validate=="Y") && (Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	
	else if (Cont_Value!="")
	{
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if (!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") ||(str == " ") || (str >= 0 && str <=9)))
			{	
				errMsg="Enter alphabets or integers in " + Cont_Name;
				return false;
			}
		}
	}
	else
		return true;
	return true;
}

//Function added by Sharath on 4th June 2003.
// function to check only alphabets, numbers, Underscore & Hyphen
function AlphaNumHyphen(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;

	if ((Cont_Validate=="Y") && (chkBlankSpaces(Cont_Value,Cont_Name,Cont_Validate)==false))
	{
			errMsg=Cont_Name + " cannot be blank";
			return false;
	}
	else if ((Cont_Validate=="Y") && (Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}

	else if (Cont_Value!="")
	{
	    var startsWith = Cont_Value.charAt(0);
	    if(( (startsWith) == "_" || ( startsWith )== "-" || ( startsWith >= 0 && startsWith <= 9 ) ))
	    {
           errMsg="Should start with valid Characters " + Cont_Name;
		   return false;
	    }
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if (!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") ||(str == " ") || (str >= 0 && str <=9) || (str == "_")|| (str == "-")))
			{
				errMsg="Enter alphabets or integers in " + Cont_Name;
				return false;
			}
		}
	}

	return true;
}


function AlphaNumSpace(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") && (chkBlankSpaces(Cont_Value,Cont_Name,Cont_Validate)==false))
	{
			errMsg=Cont_Name + " cannot be blank";
			return false;
	}
	else if ((Cont_Validate=="Y") && (Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	
	else if (Cont_Value!="")
	{
		for(i=0;i<Cont_Value.length;i++)
		{
			var str=Cont_Value.charAt(i)
			if ((!((str >= "A" && str <= "Z" ) || (str >= "a" && str <= "z") || (str >= 0 && str <=9))) || (str==" "))
			{	
				errMsg="Enter alphabets or integers in " + Cont_Name + " and there should not be any blank spaces  between charecters";
				return false;
			}
		}
	}
	else
		return true;
}

function chkNum(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	if ((Cont_Validate=="Y") && (chkBlankSpaces(Cont_Value,Cont_Name,Cont_Validate)==false))
	{
			errMsg=Cont_Name + " cannot be blank";
			return false;
	}
	else if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	else if (Cont_Value!="")
	{
		if(isNaN(Cont_Value))
		{
			//errMsg="Enter a valid number in " + Cont_Name;
			errMsg="Enter charcters only " + Cont_Name;
			return false;
		}	
	}
	else
		return true;
}

function chkNumZero(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	else if (Cont_Value!="")
	{
		if(isNaN(Cont_Value))
		{
			errMsg="Enter a valid number in " + Cont_Name;
			return false;
		}
		else if ((Cont_Value < 1)==true)
		{
		errMsg=Cont_Name + " cannot be lessthan or equal to ZERO";
		return false;
		}	
	}
	else
		return true;
}


function chkCurrency(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") && (chkBlankSpaces(Cont_Value,Cont_Name,Cont_Validate)==false))
	{
			errMsg=Cont_Name + " cannot be blank";
			return false;
	}
	else if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		alert (Cont_Name + " cannot be blank")
		return false;
	}
	else if (Cont_Value!="")
	{
		var num = new Number(Cont_Value);
		if (isNaN(num))
		{
			errMsg="Enter valid Value in " + Cont_Name;
			return false;
		}		
	}
	else
		return true;
}

function chkCurrencyZero(input,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	
	if ((Cont_Validate=="Y") &&(Cont_Value.length==0))
	{
		alert (Cont_Name + " cannot be blank")
		return false;
	}
	else if (Cont_Value!="")
	{
		var num = new Number(Cont_Value);
		if (isNaN(num))
		{
			errMsg="Enter valid Value in " + Cont_Name;
			return false;
		}
		else if ((Cont_Value < 1)==true)
		{
		errMsg=Cont_Name + " cannot be lessthan or equal to ZERO";
		return false;
		}
	}
	else
		return true;		
}

function FieldLength(input,control,compulsory,fieldlen)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	var Cont_Length=fieldlen;
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	else if (Cont_Value.length > Cont_Length)
	{
		alert (Cont_Name + " Field length cannot be greater than " + Cont_Length + " charecters")
		return false;
	}
	else
		return true;
} 


function chkPassword(input,cinput,control,compulsory)
{
	var Cont_Value = input;
	var Cont_Name =control;
	var Cont_Validate=compulsory;
	var cnfPassword=cinput;
	
	if ((Cont_Value=="") && (Cont_Validate=="Y"))
	{
		errMsg=Cont_Name + " cannot be blank";
		return false;
	}
	else if ((cnfPassword=="") && (Cont_Validate=="Y"))
	{
		errMsg="Confirm " + Cont_Name + " field cannot be blank";
		return false;
	}
	else if (Cont_Value != cnfPassword)
	{
		errMsg="Password and Confirm Password must be same";
		return false;
	}
	else
		return true;
}



function logout()
{	
	document.parentWindow.parent.location="logout.asp"
		
}
function chkURL(url,textfield)
{  
   url = url.toLowerCase();
   while(url.charAt(0)== " ")    
     {
	    url = url.substring(1,url.length);
     }
	textfield.value	=	url;
	 if (url.substring(0,7)== "http://")
     {
	 	 return true;
	 }
	 else
	 {
	    errMsg="URL should start with http://";
		return false;
	 }

}
// to refresh the form when a record is deleted
function refreshView(url) {

window.parent.frames["fr2"].location=url;

}

//to check the length of combo value
function ComboCheck(input,control)
{
	var Cont_Value = input;
	var Cont_Name = control;
	
	if (Cont_Value.length ==0)
	{
		errMsg="No item is selected in " + Cont_Name;
		return false;
		
	}
}

function isCharcters(s)
{
   // Search through string's characters one by one
    // until we find a numeric character.
    // When we do, return false; if we don't, return true.

    for (var i = 0; i < s.length; i++)
    {
	// Check that current character is number.
	var c = s.charAt(i);

	if (!isLetter(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isLetter (c)
{
	return ( ( ( c >= "a" ) && ( c <= "z" ) ) || ( ( c >= "A" ) && ( c <= "Z" ) ) || ( c == "-" ) || ( c == " " ) )
}

function CompareDate(date1,date2)
{
	var dtmBidDate=date1;
	var dtmLeadDate=date2;
	
	var Byear
	var Lyear
	var Lmon
	var Bmon
	var Lday
	var Bday
	
	var MonPosLDate = dtmLeadDate.indexOf("/",-1)
	var DayPosLDate = dtmLeadDate.lastIndexOf("/")
	var MonPosBDate = dtmBidDate.indexOf("/",-1)
	var DayPosBDate = dtmBidDate.lastIndexOf("/")

	Lyear=dtmLeadDate.substr(eval(DayPosLDate+1),4)
	Byear=dtmBidDate.substr(eval(DayPosBDate+1),4)

	Lmon=dtmLeadDate.substr(0,MonPosLDate)
	Bmon=dtmBidDate.substr(0,MonPosBDate)

	Lday=dtmLeadDate.substr(eval(MonPosLDate+1),eval(DayPosLDate-MonPosLDate-1))
	Bday=dtmBidDate.substr(eval(MonPosBDate+1),eval(DayPosBDate-MonPosBDate-1))
		
	if (eval(Lyear)>eval(Byear))
	{
		return true;
	}
	else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)>eval(Bmon)))
	{
		return true;
	}
	else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)>eval(Bday)))
	{
		return true;
	}
	else if ((eval(Lyear)==eval(Byear)) && (eval(Lmon)== eval(Bmon)) && (eval(Lday)==eval(Bday)))
	{
		return true;
	}
	else
	{
		return false;
	}
}

// added by ravikanth on 17 Sep 2003
function addDupPartNumber(fldName,lblname)
{
    var htmltext = '<table style=NArialL cellspacing=0 cellpadding=0 width="100%" border=0><tr><td width="21%"><font class="NArialL"><font color=green>'+lblname+':</font></font></td><td width="28%"><input type=text name='+ fldName +' class=txfield size="17" maxlength="50" /></td><td colspan=3>&nbsp;</td></tr></table>';
    var pa1 = document.getElementById ("font1");
    pa1.insertAdjacentHTML ('BeforeEnd',htmltext);

}

// check for duplicate names here
function checkDupInProduct(product,dupProduct)
{
	var paa = document.getElementById("message");
	product.value = trim(product.value);
	if(dupProduct != null)
	{
		if( typeof dupProduct.length == 'undefined' )
		{
			dupProduct.value = trim(dupProduct.value);
			if( product.value == dupProduct.value)
			{
				paa.innerHTML = "Two Part numbers cannot be same";	
				dupProduct.focus();
				return 0;
			}
		}
		else
		{
			for( var x=0; x < dupProduct.length; x++ )
			{
				dupProduct[x].value = trim(dupProduct[x].value);
				if(trim(dupProduct[x].value)!='' && product.value == dupProduct[x].value)
				{
					paa.innerHTML = "Two Part numbers cannot be same";	
					dupProduct[x].focus();
					return x;
				}							
			}
			
			for( var x=0; x < dupProduct.length-1; x++ )
			{
				for( var y = x+1; y < dupProduct.length; y++ )
				{
					if(trim(dupProduct[x].value)!='' && trim(dupProduct[y].value)!='' && dupProduct[x].value == dupProduct[y].value)
					{
						paa.innerHTML = "Two Part numbers cannot be same";	
						dupProduct[y].focus();
						return y;
					}
				}
			}
		}
	}
	return -1;
}
// Added by Sharath on 19th April 04 for Floating Point Numbers Formatting

function parseDec(val,places,sep) {

    // This function takes two arguments:
    //   (string || number)  val
    //            (integer)  places
    //             (string)  sep
    // val is the numeric string or number to parse
    // places represents the number of decimal
    // places to return at the end of the parse.
    // sep is an optional string to be used to separate
    // the whole units from the decimal units (default: '.')

    val = round(val,places);

    val = '' + val;
        // Implicitly cast val to (string)

    if (!sep) {
        sep = '.';
        // If separator isn't specified, then use a decimal point '.'
    }

    if (!places) { places = 0; }
    places = parseInt(places);
        // Make sure places is an integer

    if (( !parseFloat(val) ) || ( parseFloat(val) != val )) {
        // If val is null, zero, NaN, or not specified, then
        // assume val to be zero.  Add 'places' number of zeros after
        // the separator 'sep', and then return the value.  We're done here.
        val = '0';
        if (places > 0) {
            val += sep;
            while (val.substring((val.indexOf(sep))).length <= places) {
                val += '0';
            }
        }
        return val;
    }

    if ((val.indexOf('.') > -1) && (sep != '.')) {
        val = val.substring(0,val.indexOf('.')) + sep + val.substring(val.indexOf('.')+1);
            // If we're using a separator other than '.' then convert now.
    }

    if (val.indexOf(sep) > -1) {
        // If our val has a separator, then cut our value
        // into pre and post 'decimal' based upon the separator.
        pre = val.substring(0,val.indexOf(sep));
        post = val.substring(val.indexOf(sep)+1);
    } else {
        // Otherwise pre gets everything and post gets nothing.
        pre = val;
        post = '';
    }

    if (places > 0) {
        // If we're dealing with a decimal then...

        post = post.substring(0,(places+1));
            // We care most about the digit after 'places'

        if (post.length > places) {
            // If we have trailing decimal places then...

            //alert (parseInt(post.substring(post.length - 1)));

            if ( parseInt(post.substring(post.length - 1)) > 4 ) {
                post = '' + Math.round(parseFloat(post) / 10);
                //post = '' + post.substring(0,post.length - 2) + (1/Math.pow(10,places));
                //post = ('' + post.substring(0,post.length - 2)) + (parseInt(post.substring(post.length - 1)) + 1);
            } else {
                post = post.substring(0,post.length - 1);
            }
        }

        if (post.length > places) {
            pre = parseInt(pre)+1;
            post ="00";
        } else if (post.length < places) {
            while (post.length < places) {
                post += '0';
            }
        }

    } else {

        if (parseInt((post.substring(0,1))) > 4) {
            pre = '' + (parseInt(pre) + 1);
        } else {
            pre = '' + (parseInt(pre));
        }
        post = '';
    }

    sep = (post.length > 0) ? sep : '';
        // Should we use a separator?

    val = parseInt(pre) + sep + post;
        // Rebuild val

    return val;
}

function parseMoney(val,sep) {

    // Specialized version of parseDec useful for
    // parsing money-related data.  Arguments:
    //   (string || number)  val
    //             (string)  sep
    // val is the monetary value to be parsed,
    // sep is an optional decimal separator (default: '.')

    return parseDec(val,2,sep);
}

//Added by Rohan on Dec 15 2003
//It returns the number rounded to the number of decimal places specified
//if decimal spaces are not specified then it is taken as 2
function round( number, maxDecimalPlaces )
{
    maxDecimalPlaces = ( !maxDecimalPlaces ? 2 : maxDecimalPlaces);
    return Math.round( number * Math.pow( 10, maxDecimalPlaces )) / Math.pow( 10, maxDecimalPlaces ) ;
}

//Added by Rohan on Dec 29th 2003
//This method validates the text input by accepting only numerics
//This method will also allow one period ( . ) to be entered into the text field
function amountFieldKeyPress( amountField )
{
    // 46 is for period ( . )
    //48 is for 0
    //57 is for 9
    if( ( event.keyCode < 48 || event.keyCode > 57 ) && ( event.keyCode != 46 ) )
    {
        event.returnValue = false;
    }
    else if( event.keyCode == 46 )
    {
        if( amountField.value.indexOf( "." ) >= 0 )
        {
            event.returnValue = false;
        }
    }
}

//Added by Rohan on Dec 29th 2003
//This method validates the text input by accepting only numerics
function numericFieldKeyPress( numericField )
{
    //48 is for 0
    //57 is for 9
    if( ( event.keyCode < 48 || event.keyCode > 57 )  )
    {
        event.returnValue = false;
    }
}

//Added by Rohan on Dec 29th 2003
//This method will parse the value inthe amount fields to two decimal places
function amountFieldLostFocus( amountField )
{
    amountField.value = parseMoney( amountField.value )
}

// Added by SharatH on 30th April 04 for Numeric validations.
function removeCommasAndDollar( Num )
{
    var tempValue = "";
    var temp = "";

    for( j=0; j < Num.length; j++ )
    {
        temp = Num.charAt(j)
        if( temp >= 0 || temp <= 9 || temp == "." || temp == "-" )
        {
            tempValue = tempValue + Num.charAt(j);
        }
    }
    tempValue = parseDec( round( parseFloat( tempValue ) ), 2, '.' );
    return tempValue;
}

function removeCommas( Num )
{
    var tempValue = "";
    var temp = "";

    var tempString = Num.lastIndexOf("."); // Get the index no of Dot

    // If Dot any decimals exist then substring it.
    if( tempString > -1 )
    {
        Num = ( Num.substring( 0, tempString ) );
    }
    for( j=0; j < Num.length; j++ )
    {
        temp = Num.charAt(j)
        if( temp >= 0 || temp <= 9 )
        {
            tempValue = tempValue + Num.charAt(j);
        }
    }
    return tempValue;
}

function placeCommasForAmounts( obj )
{
    var form = document.receivingsTransactionForm;
    var Num = obj;
    var tempValue = removeCommasAndDollar( Num );

    if( parseFloat( tempValue ) > 0 )
    {
        Num = tempValue;

        var newNum = "";
        var newNum2 = "";
        var count = 0;

        //check for decimal number
        if ( Num.indexOf('.') != -1 )
        {  //number ends with a decimal point
            if (Num.indexOf('.') == Num.length-1)
            {
                Num += "00";
            }
            if (Num.indexOf('.') == Num.length-2)
            { //number ends with a single digit
                Num += "0";
            }

            var a = Num.split(".");
            Num = a[0];   //the part we will commify
            var end = a[1] //the decimal place we will ignore and add back later
        }
        else {var end = "00";}

        //this loop actually adds the commas
        for (var k = Num.length-1; k >= 0; k--)
        {
          var oneChar = Num.charAt(k);
          if (count == 3)
          {
            newNum += ",";
            newNum += oneChar;
            count = 1;
            continue;
          }
          else
          {
            newNum += oneChar;
            count ++;
          }
       }  //but now the string is reversed!

      //re-reverse the string
      for (var k = newNum.length-1; k >= 0; k--)
      {
          var oneChar = newNum.charAt(k);
          newNum2 += oneChar;
      }

       // add dollar sign and decimal ending from above
       newNum2 = "$" + newNum2 + "." + end;
   }
   else
   {
        newNum2 = "$0.00";
   }
   return newNum2;
}

function placeCommasForUnits( obj )
{
    var form = document.receivingsTransactionForm;
    var Num = obj;
    var tempValue = removeCommas( Num );

    Num = tempValue;

    var newNum = "";
    var newNum2 = "";
    var count = 0;

    //this loop actually adds the commas
    for (var k = Num.length-1; k >= 0; k--)
    {
      var oneChar = Num.charAt(k);
      if (count == 3)
      {
        newNum += ",";
        newNum += oneChar;
        count = 1;
        continue;
      }
      else
      {
        newNum += oneChar;
        count ++;
      }
   }  //but now the string is reversed!

  //re-reverse the string
  for (var k = newNum.length-1; k >= 0; k--){
      var oneChar = newNum.charAt(k);
      newNum2 += oneChar;
  }
   return newNum2;
}


// Added by Krishna Prasad on 13 May 2004 , to allow only two decimals in price text box 

function removePrePostSpaces(lineItemElement)
{
	if(typeof lineItemElement.length == 'undefined' )
	{
        lineItemElement.value=lineItemElement.value.replace(/^\s+/,'').replace(/\s+$/,'');
	}
	else
	{
		for( var x=0; x < lineItemElement.length; x++ )
		{
            lineItemElement[x].value=lineItemElement[x].value.replace(/^\s+/,'').replace(/\s+$/,'');
		}
	}
}

function testCVS()
{}
// Added by veeru on 13th May 2004 to restrict alphabets and special characters
function restrictCharacters(element,iPart,dPart)
{

    prevPrice = element.value;

    p_array = prevPrice.split(".");
	var amt = element.value ;
	var n   = 0;
	// does n't accept other than numbers and "."
	if (event.keyCode < 46 || event.keyCode > 57 || event.keyCode == 47 )
	{
		event.returnValue = false;
	}
	// does n't accept more than one .
	for( var i = 0 ; i < amt.length ; i++)
	{
		if ( amt.charAt(i) == ".")
		{
			n++;
		}
	}
	if( n > 0 || prevPrice == '' )
	{
		if (event.keyCode == 46 )
		{
			event.returnValue = false;
		}
	}
	if ( p_array.length > 1 )
	{
		if( iPart > 0 && p_array[0].length > iPart )
		{
		    event.returnValue = false;
		}
		if( dPart > 0 && p_array[1].length > dPart )
		{
		    event.returnValue = false;
		}
    }
    else
    {
        if( prevPrice.length >= iPart && event.keyCode != 46)
        {
            event.returnValue = false;
        }
    }
}
// Added by veeru on 13th May 2004 to restrict number places for integer part and decimal part in an ammount
function restrictAmt(element,iPart,dPart)
{
	amt     = element.value;
	array   = amt.split(".");
	if( array.length > 1 )
	{
		if( dPart > 0 && array[1].length > dPart )
		{
		    element.value = prevPrice;
		}
		if( iPart > 0 && array[0].length > iPart )
		{
		    element.value = prevPrice;
		}
	}
	else if ( amt.length > iPart )
	{
        element.value = prevPrice;
	}
}

// Added by SureshReddy on [09 JUNE 2004] to restrict maximum length for TextArea
function setTextAreaMaxLength(element,maxSize) {

    if(element.value.length > maxSize){
        element.value= element.value.substring(0,maxSize);
        element.focus();
    }

}
//Added by varma(16 aug 2004) to restrict Single Quotes(').
function restrictSingleQuote(elment)
 {
   if(event.keyCode == 39 || event.keyCode == 34)
   {
        event.returnValue = false;
   }
 }

 //Added by Sujan on  20th Nov 2004
function isBeforeToday( pDate, control )  //dateformat: mm/dd/yyyy
{
    if ( pDate == 'undefined'|| pDate.value == '' || pDate.length == 0 )
    {
        return false;
    }
	now   = new Date();
	now.setHours ( 23,59,59,999);

	idx1 = pDate.indexOf ( '/' ) ;
	idx2 = pDate.lastIndexOf ( '/' );
	month= ( pDate.substring (  0 ,idx1 ) );
	day =  pDate.substring ( (idx1+1),idx2);
	year=  pDate.substring ( ( idx2+1 ) );

	passedDate = new Date( year,month-1,day, 23,59,59,999);

	if ( passedDate.valueOf() < now.valueOf ( ) )
	{
	    errMsg = "<li>" + control + " can not be prior to today's date</li>";
		return true;
	}
    return false;
}

function validatePhoneNumber( phoneNbrElement )
{
    var validKeys = "1234567890()- ";
    var keyCode = window.event.keyCode;
    if ( ( keyCode >= 97 && keyCode <= 122) || (keyCode >= 65 && keyCode <=  90 ) || validKeys.indexOf( String.fromCharCode(keyCode) ) != -1)
    {
        event.returnValue = true;
    }
    else
    {
        event.returnValue = false;
    }

}

//added by Murali Krishna on 19 Jan 2005
function allowInteger()
{
    var validKeys = "1234567890";
    var keyCode = window.event.keyCode;
    if ( validKeys.indexOf( String.fromCharCode(keyCode) ) != -1)
    {
        event.returnValue = true;
    }
    else
    {
        event.returnValue = false;
    }
}
// This method restricts all the special charecters -- Veeru 4th March 2005
function restrictSpecialChars()
{
    var validKeys = "`~!@#$%^&*()-_=+|[{]};:,<.>/?\\\'\"";
    var keyCode = window.event.keyCode;
    if ( validKeys.indexOf( String.fromCharCode(keyCode) ) == -1)
    {
        event.returnValue = true;
    }
    else
    {
        event.returnValue = false;
    }
}

function notAllowedSpecialChars()
{
    var validKeys = "0123456789-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var keyCode = window.event.keyCode;
    if ( validKeys.indexOf( String.fromCharCode(keyCode) ) != -1)
    {
        event.returnValue = true;
        return true;
    }
    else
    {
        event.returnValue = false;
        return false;
    }
}

function checkFloatPrice( input, control, compulsory )
{
	var Cont_Name       = control;
	var Cont_Validate   = compulsory;
	var Cont_Value      = input;

	if( ( Cont_Validate == "Y" ) && ( Cont_Value.length == 0 ) )
	{
		errMsg = Cont_Name + " cannot be blank";
		return false;
	}
	else if( Cont_Value != "" )
    {
        if( isNaN( Cont_Value ) || ( Cont_Value.charAt( 0 ) == " " ) || ( ( Cont_Value.charAt( 0 ) == 0 ) && ( Cont_Value.charAt( 1 ) != "." ) )  )
        {
            errMsg = Cont_Name + " should be valid number and first digit can not be space or zero ";
            return false;
        }
        for( i = 0; i < Cont_Value.length; i++ )
        {
            var ch  = Cont_Value.charAt( i );
            if( ch == '.' )
            {
                var substr = Cont_Value.substring( i+1, Cont_Value.length );
                if( substr.length > 3 )
                {
                    errMsg = Cont_Name + " can contain only three decimals ";
                    return false;
                }
            }
        }
        if( Cont_Value < 0 )
        {
            errMsg = Cont_Name + " can not be less than zero ";
            return false;
        }
        return true;
    }
    else
    {
        return true;
    }
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

/*
    returns no of days elapsed from date1 to date2.
*/
function daysElapsed( date1, date2 ) 
{   
    var difference = Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0) - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);
    return difference/1000/60/60/24;
}